import 'package:flutter/material.dart';

import '../../utils/Configs/ai_config.dart';
import '../../utils/models/ai_model.dart';
import '../../utils/utils.dart';
import '../../utils/zz_navigator.dart';
import '../chat/chat.dart';

class AiChatCell extends StatefulWidget {
  final AiModel model;
  const AiChatCell({super.key, required this.model});

  @override
  State<AiChatCell> createState() => _AiChatCellState();
}

class _AiChatCellState extends State<AiChatCell> {
  @override
  void initState() {
    super.initState();

    eventBus.on<AiLikedChanged>().listen((e) {
      // mounted ? setState(() {}) : null;
      setState(() {});
    });
  }

  _chatsTap() {
    ZZNavigator.push(
        widget: ChatWidget(
      model: widget.model,
    ));
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => _chatsTap(),
      child: Padding(
          padding: const EdgeInsets.only(left: 10, right: 10),
          child: Row(
            children: [
              ClipOval(
                child: Image.asset(
                  widget.model.header ?? "assets/images/Rectangle 49.png",
                  width: 50,
                ),
              ),
              const SizedBox(width: 10),
              Expanded(
                  child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    widget.model.title ?? "",
                    style: const TextStyle(color: Colors.white, fontSize: 16),
                  ),
                  Text(
                    widget.model.description,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: const TextStyle(color: Colors.white60, fontSize: 14),
                  ),
                ],
              ))
            ],
          )),
    );
  }
}
